import axios from '@/utils/request/axios';
import { WxMsgRecord } from 'common/src/apis';

export class UploadShipData {
  // /** 船舶类型 */
  // type: string;
  // /** 路径不带db名字 */
  // path: string;
  /** xx.db */
  dbname: File;
}

export async function uploadShipData(data: FormData) {
  const res = await axios({
    method: 'post',
    url: '/rollpitch/analysis',
    data,
    headers: { 'Content-Type': 'multipart/form-data' },
  });
  return res.data;
}

export class GetShipDataRecordParams {
  page: number;
  length: number;
}

export class ShipDataRecord {
  dbname: string;
  id: number;
  /** 数据量大小 *条数据 */
  count: number;
  /** 训练状态 0:未训练;1:训练中;2:已训练 */
  status: number;
  /** 舰船类型 */
  type: number;
  /** 入库时间2023-06-01 08:00:00 */
  created_time: string;
  /** 数据开始时间2023-06-01 08:00:00 */
  stime: string;
  /** 数据结束时间2023-06-01 08:00:00 */
  etime: string;
}

export async function getShipDataRecord(params: GetShipDataRecordParams) {
  const res = await axios({
    method: 'get',
    url: `/rollpitch`,
    params,
  });
  return {
    list: res.data.data.list as ShipDataRecord[],
    total: res.data.data.total || 0,
  };
}

export async function getShipDataCompare(params: GetShipDataRecordParams) {
  const res = await axios({
    method: 'get',
    url: `/rollpitch/record`,
    params,
  });
  return res.data
}


export class GetModelRecordParams {
  page: number;
  length: number;
}

export class ModelRecord {
  id: number;
  /** 是否激活 1: 激活 0: 未激活 */
  active: number;
  /** 入库时间2023-06-01 08:00:00 */
  created_time: string;
  /** 版本号 */
  name: string;
}

export async function getModelRecords(params: GetModelRecordParams) {
  const res = await axios({
    method: 'get',
    url: `/rollpitch/models`,
    params,
  });
  return {
    list: res.data.data.list as ModelRecord[],
    total: res.data.data.total || 0,
  };
}

/** 激活模型版本 */
export async function activeModelById(id: number) {
  const res = await axios({
    method: 'post',
    url: `/rollpitch/active/${id}`,
  });
  return res.data;
}

export class GetWxMsgRecordParams {
  page: number;
  length: number;
  content?: string;
  name?: string;
}

/** 分页获取危险报文数据 */
export async function getWxMsgRecord(params: GetWxMsgRecordParams) {
  const res = await axios({
    method: 'get',
    url: `/sp/regions/abj/list`,
    params,
  });
  return {
    list: res.data.data.list as WxMsgRecord[],
    total: res.data.data.total || 0,
  };
}

export class UploadWxMsg {
  /** xx.obj */
  abj: File;
}

/** 导入危险报文数据 */
export async function uploadWxMsg(data: FormData) {
  const res = await axios({
    method: 'post',
    url: '/sp/regions/wx/abj',
    data,
    headers: { 'Content-Type': 'multipart/form-data' },
  });
  return res.data;
}

/** 删除危险报文数据 */
export async function deleteWxMsg(id: number) {
  const res = await axios({
    method: 'delete',
    url: `/sp/regions/abj/${id}`,
  });
  return res.data;
}

export class GetWeatherRecordParams {
  page: number;
  length: number;
}

export class WeatherRecord {
  id: number;
  /** 入库时间2023-06-01 08:00:00 */
  created_time: string;
  /** 版本号 */
  name: string;
}

export async function getWeatherRecords(params: GetWeatherRecordParams) {
  const res = await axios({
    method: 'get',
    url: `/rollpitch/models`,
    params,
  });
  return {
    // list: res.data.data.list as WeatherRecord[],
    // total: res.data.data.total || 0,
    list: [] as WeatherRecord[],
    total: 0,
  };
}

/** 等压线json数据 */
export async function getPressureLine(data) {
  const res = await axios({
    method: 'post',
    url: `/process/isonline`,
    baseURL: '/draw',
    data
  });
  return res.data.data;
}

/** task数据 */
export async function getTaskFactorStatus(params) {
  const res = await axios({
    method: 'get',
    url: `/task/meteos`,
    params
  });
  return res.data.data;
}
